/*
 * GeneticInfoPanel.java
 *
 * Created on 24 kwiecień 2008, 11:03
 */

package flp.gui.view.ant;

import flp.Layout;
import flp.solvers.ant.AntSettings;

/**
 * Klasa reprezentujaca panel obrazujacy dane liczbowe
 * dla algorytmu mrowkowego.
 *
 * @author  Necro
 */
public class AntInfoPanel extends javax.swing.JPanel
{
     /**
     * Metoda ustawiajaca nowa wartosc tekstowa pola
     * z zegarem mierzacym czas trwania obliczen.
     * 
     * @param newText Nowy tekst dla etykiety.
     */
    public void setTimeLabelText(String newText){
        this.timerLabel.setText(newText);
    }
    
     /**
     * Konstruktor nowego panelu, przyjmuje dane bedace
     * ustawieniami algorytmu.
     * 
     * @param settings Ustawienia algorytmu.
     */   
    public AntInfoPanel(AntSettings settings)
    {
        initComponents();
        maxIterValueLabel.setText("" + settings.getMaxIterations());
        maxWithNoChangeValueLabel.setText("" + settings.getIterationsWithNoChange());
        evaporationRatioValueLabel.setText(String.format("%.2f", settings.getEvaporationRatio()));
        antCountValueLabel.setText("" + settings.getAntNumber());
        
        resultLabel.setVisible(false);
        resultValueLabel.setVisible(false);

        iterationProgressBar.setMinimum(0);
        iterationProgressBar.setMaximum(settings.getMaxIterations());
        iterationProgressBar.setStringPainted(true);
        iterationProgressBar.setToolTipText("Pasek postępu dla wykonywanych iteracji");
    }

     /**
     * Metoda aktualizujaca etykiety panelu.
     * 
     * @param newIter Numer iteracji.
     * @param newLocalTopCost Lokalnie najlepszy koszt.
     * @param newGlobalTopCost Globalnie najlepszy koszt.
     */
    public void updateValues(int newIter, int newLocalTopCost, int newGlobalTopCost){
       markOnBar(newIter);
       topLocalCostValueLabel.setText(Integer.toString(newLocalTopCost));
       topGlobalCostValueLabel.setText(Integer.toString(newGlobalTopCost));
    }

     /**
     * Metoda wywolywana po zakonczeniu obliczen dla danego przypadku
     * wyswietla dla niego rozwiazanie problemu.
     * 
     * @param bestLayout Najlepszy Layout znaleziony podczas optymalizacji.
     */
    public void showResult(Layout bestLayout){
       resultValueLabel.setText(""+bestLayout.toString2()+"    cost: "+topGlobalCostValueLabel.getText());
       
       resultLabel.setVisible(true);
       resultValueLabel.setVisible(true);
       
       topLocalCostLabel.setEnabled(false);
       topLocalCostValueLabel.setEnabled(false);
       topGlobalCostLabel.setEnabled(false);
       topGlobalCostValueLabel.setEnabled(false);
    }
    
    /**
     * Metoda zaznaczajaca postep na pasku postepu.
     * 
     * @param tryVal Wartosc do zaznaczenia.
     */
     private void markOnBar(int iteration) {
        iterationProgressBar.setValue(iteration);
        iterationProgressBar.setString(iteration + " / " + maxIterValueLabel.getText());
    }
     
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        iterationProgressBar = new javax.swing.JProgressBar();
        resultLabel = new javax.swing.JLabel();
        resultValueLabel = new javax.swing.JLabel();
        titlePrefixLabel = new javax.swing.JLabel();
        titleLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        timerLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        topLocalCostLabel = new javax.swing.JLabel();
        topLocalCostValueLabel = new javax.swing.JLabel();
        topGlobalCostValueLabel = new javax.swing.JLabel();
        topGlobalCostLabel = new javax.swing.JLabel();
        geneticSettingsPanel = new javax.swing.JPanel();
        maxIterLabel1 = new javax.swing.JLabel();
        maxSCIterLabel1 = new javax.swing.JLabel();
        maxWithNoChangeValueLabel = new javax.swing.JLabel();
        maxIterValueLabel = new javax.swing.JLabel();
        antCountLabel = new javax.swing.JLabel();
        antCountValueLabel = new javax.swing.JLabel();
        evaporationRatioLabel = new javax.swing.JLabel();
        evaporationRatioValueLabel = new javax.swing.JLabel();

        resultLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        resultLabel.setText("WYNIK:");

        resultValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        resultValueLabel.setForeground(new java.awt.Color(0, 0, 102));
        resultValueLabel.setText("przykladowy wynik");

        titlePrefixLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        titlePrefixLabel.setText("Do optymalizacji zastosowano:");

        titleLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        titleLabel.setForeground(new java.awt.Color(0, 102, 0));
        titleLabel.setText("ALGORYTM MRÓWKOWY");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setForeground(new java.awt.Color(0, 0, 102));
        jLabel1.setText("Czas trwania obliczeń:");

        timerLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        timerLabel.setForeground(new java.awt.Color(0, 0, 102));
        timerLabel.setText("00:00");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Monitor wartości"));

        topLocalCostLabel.setText("Najlepszy koszt dla iteracji:");

        topLocalCostValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        topLocalCostValueLabel.setText("0");

        topGlobalCostValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        topGlobalCostValueLabel.setText("0");

        topGlobalCostLabel.setText("Najlepszy koszt globalnie:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(topLocalCostLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(topLocalCostValueLabel))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(topGlobalCostLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(topGlobalCostValueLabel)))
                .addContainerGap(54, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(topLocalCostLabel)
                    .addComponent(topLocalCostValueLabel))
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(topGlobalCostLabel)
                    .addComponent(topGlobalCostValueLabel))
                .addContainerGap(51, Short.MAX_VALUE))
        );

        geneticSettingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Ustawienia algorytmu"));

        maxIterLabel1.setText("Maksymalna ilość iteracji:");

        maxSCIterLabel1.setText("Maksymalna ilość iteracji ze spełnionym warunkiem stopu:");

        maxWithNoChangeValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        maxWithNoChangeValueLabel.setText("0");

        maxIterValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        maxIterValueLabel.setText("0");

        antCountLabel.setText("Ilość mrówek:");

        antCountValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        antCountValueLabel.setText("0");

        evaporationRatioLabel.setText("Współczynnik parowania:");

        evaporationRatioValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        evaporationRatioValueLabel.setText("0");

        javax.swing.GroupLayout geneticSettingsPanelLayout = new javax.swing.GroupLayout(geneticSettingsPanel);
        geneticSettingsPanel.setLayout(geneticSettingsPanelLayout);
        geneticSettingsPanelLayout.setHorizontalGroup(
            geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(geneticSettingsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(geneticSettingsPanelLayout.createSequentialGroup()
                        .addComponent(maxIterLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(maxIterValueLabel))
                    .addGroup(geneticSettingsPanelLayout.createSequentialGroup()
                        .addComponent(maxSCIterLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(maxWithNoChangeValueLabel))
                    .addGroup(geneticSettingsPanelLayout.createSequentialGroup()
                        .addComponent(antCountLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(antCountValueLabel))
                    .addGroup(geneticSettingsPanelLayout.createSequentialGroup()
                        .addComponent(evaporationRatioLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(evaporationRatioValueLabel)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        geneticSettingsPanelLayout.setVerticalGroup(
            geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(geneticSettingsPanelLayout.createSequentialGroup()
                .addGroup(geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxIterLabel1)
                    .addComponent(maxIterValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxSCIterLabel1)
                    .addComponent(maxWithNoChangeValueLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(antCountLabel)
                    .addComponent(antCountValueLabel))
                .addGap(6, 6, 6)
                .addGroup(geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(evaporationRatioLabel)
                    .addComponent(evaporationRatioValueLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(iterationProgressBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(titlePrefixLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(timerLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(geneticSettingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(resultLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(resultValueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titlePrefixLabel)
                    .addComponent(titleLabel)
                    .addComponent(timerLabel)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(iterationProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(geneticSettingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resultLabel)
                    .addComponent(resultValueLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel antCountLabel;
    private javax.swing.JLabel antCountValueLabel;
    private javax.swing.JLabel evaporationRatioLabel;
    private javax.swing.JLabel evaporationRatioValueLabel;
    private javax.swing.JPanel geneticSettingsPanel;
    private javax.swing.JProgressBar iterationProgressBar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel maxIterLabel1;
    private javax.swing.JLabel maxIterValueLabel;
    private javax.swing.JLabel maxSCIterLabel1;
    private javax.swing.JLabel maxWithNoChangeValueLabel;
    private javax.swing.JLabel resultLabel;
    private javax.swing.JLabel resultValueLabel;
    private javax.swing.JLabel timerLabel;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JLabel titlePrefixLabel;
    private javax.swing.JLabel topGlobalCostLabel;
    private javax.swing.JLabel topGlobalCostValueLabel;
    private javax.swing.JLabel topLocalCostLabel;
    private javax.swing.JLabel topLocalCostValueLabel;
    // End of variables declaration//GEN-END:variables
    
}
